﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using TwitterClient2.Controller;

namespace TwitterClient2.Components
{


    public class PanelNavigation : Panel
    {
        private ImageButton navigateTo;
        private Label labelActualPanel;
        private string actualPanelName;
        private ContextMenu contextMenu;
        private MenuItem mainMenuItem;
        private MenuItem searchItem;
        private MenuItem homeItem;
        private MenuItem followersItem;
        private MenuItem friendsItem;
        private MenuItem newsItem;
        private MenuItem messagesItem;
        public const byte PANEL_HOME = 1;
        public const byte PANEL_SEARCH = 2;
        public const byte SEARCH_USER = 3;
        public const byte HOME_USER = 4;
        public const byte PANEL_FOLLOWERS = 5;
        public const byte FOLLOWERS_USERS = 6;
        public const byte PANEL_FRIENDS = 7;
        public const byte FRIENDS_USERS = 8;
        public const byte PANEL_MESSAGES = 9;
        public const byte PANEL_NEWS = 10;
        public const byte NEWS_USERS = 11;
        public const byte MESSAGES_USERS = 12;

        private TwitterClientController controller = TwitterClientController.getInstance();

        public PanelNavigation(string actualPanel, byte type)
        {
            this.actualPanelName = actualPanel;

            InitializeComponent();
            this.intializeMenuItems(type);
        }

        private void intializeMenuItems(byte type)
        {
            this.mainMenuItem = new MenuItem();
            this.mainMenuItem.Text = "Mainmenu";
            this.mainMenuItem.Click += new System.EventHandler(this.itemClicked);

            this.searchItem = new MenuItem();
            this.searchItem.Text = "Search";
            this.searchItem.Click += new System.EventHandler(this.itemClicked);

            this.homeItem = new MenuItem();
            this.homeItem.Text = "Home";
            this.homeItem.Click += new System.EventHandler(this.itemClicked);

            this.followersItem = new MenuItem();
            this.followersItem.Text = "Followers";
            this.followersItem.Click += new System.EventHandler(this.itemClicked);

            this.friendsItem = new MenuItem();
            this.friendsItem.Text = "Friends";
            this.friendsItem.Click += new System.EventHandler(this.itemClicked);

            this.newsItem = new MenuItem();
            this.newsItem.Text = "News";
            this.newsItem.Click += new System.EventHandler(this.itemClicked);

            this.messagesItem = new MenuItem();
            this.messagesItem.Text = "Messages";
            this.messagesItem.Click += new System.EventHandler(this.itemClicked);

            switch (type)
            {
                case PANEL_SEARCH:
                case PANEL_HOME:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    break;
                case SEARCH_USER:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    this.contextMenu.MenuItems.Add(this.searchItem);
                    break;
                case HOME_USER:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    this.contextMenu.MenuItems.Add(this.homeItem);
                    break;
                case PANEL_FOLLOWERS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    break;
                case FOLLOWERS_USERS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    this.contextMenu.MenuItems.Add(this.followersItem);
                    break;
                case PANEL_FRIENDS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    break;
                case FRIENDS_USERS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    this.contextMenu.MenuItems.Add(this.friendsItem);
                    break;
                case PANEL_MESSAGES:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    break;
                case PANEL_NEWS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    break;
                case NEWS_USERS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    this.contextMenu.MenuItems.Add(this.newsItem);
                    break;
                case MESSAGES_USERS:
                    this.contextMenu.MenuItems.Add(this.mainMenuItem);
                    this.contextMenu.MenuItems.Add(this.messagesItem);
                    break;
                default:
                    break;

            }

        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PanelNavigation));
            this.contextMenu = new System.Windows.Forms.ContextMenu();
            this.labelActualPanel = new System.Windows.Forms.Label();
            this.navigateTo = new TwitterClient2.Components.ImageButton();
            this.SuspendLayout();
            // 
            // labelActualPanel
            // 
            this.labelActualPanel.Font = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.labelActualPanel.Location = new System.Drawing.Point(3, 3);
            this.labelActualPanel.Name = "labelActualPanel";
            this.labelActualPanel.Text = this.actualPanelName;
            this.labelActualPanel.Size = new System.Drawing.Size(100, 14);
            // 
            // navigateTo
            // 
            this.navigateTo.ContextMenu = this.contextMenu;
            this.navigateTo.Location = new System.Drawing.Point(102, 3);
            this.navigateTo.MousePressedImage = ((System.Drawing.Image)(resources.GetObject("navigateTo.MousePressedImage")));
            this.navigateTo.Name = "navigateTo";
            this.navigateTo.NormalImage = ((System.Drawing.Image)(resources.GetObject("navigateTo.NormalImage")));
            this.navigateTo.Size = new System.Drawing.Size(15, 14);
            this.navigateTo.TabIndex = 0;
            this.navigateTo.Text = "imageButton1";
            // 
            // PanelNavigation
            // 
            this.Controls.Add(this.labelActualPanel);
            this.Controls.Add(this.navigateTo);
            this.Size = new System.Drawing.Size(220, 20);
            this.ResumeLayout(false);

        }


        private void itemClicked(object sender, EventArgs e)
        {
            if (sender == this.mainMenuItem)
            {
                TwitterClientEvent tEvent = new TwitterClientEvent();
                tEvent.paramList.Add(this.Parent);
                this.controller.performUserInput(TwitterClientController.NAVIGATION_MAINMENU_CLICK, tEvent);
            }
            else if (sender == this.searchItem)
            {
                this.controller.performUserInput(TwitterClientController.NAVIGATION_SEARCH_USER_CLICK, null);
            }
            else if (sender == this.homeItem)
            {
                this.controller.performUserInput(TwitterClientController.NAVIGATION_HOME_USER_CLICK, null);
            }
            else if (sender == this.followersItem)
            {
                this.controller.performUserInput(TwitterClientController.NAVIGATION_FOLLOWERS_USER_CLICK, null);
            }
            else if (sender == this.friendsItem)
            {
                this.controller.performUserInput(TwitterClientController.NAVIGATION_FIRENDS_USER_CLICK, null);
            }
            else if (sender == this.newsItem)
            {
                this.controller.performUserInput(TwitterClientController.NAVIGATION_NEWS_USER_CLICK, null);
            }
            else if (sender == this.messagesItem)
            {
                this.controller.performUserInput(TwitterClientController.NAVIGATION_MESSAGES_USER_CLICK, null);
            }
        }


    }
}
